//
//  CZVisitorViewController.swift
//  微博
//
//  Created by 范承志 on 16/6/11.
//  Copyright © 2016年 fanchengzhi. All rights reserved.
//

import UIKit

class CZVisitorViewController: UIViewController {
    
    //判断是否是访客视图
    var isLogin: Bool = CZUserAccountViewModel.sharedTools.isLogin
    
    //访客视图
    var visitorView: CZVisitorView?

    //加载视图
    override func loadView() {
        
        //判断是否登录
        if isLogin{
            
            //登录了就用自定义的TableView
            view = tableView
        } else {
            
            //没登录就用自定义的View
            setupVisitorView()
        }
        
    }
    
    
    //设置访客视图
    private func setupVisitorView(){
        
        //创建访客视图
        visitorView = CZVisitorView()
        
        //实例化闭包
        visitorView?.closure = {[weak self] in
            
            self?.loginClick()
        }
        //赋值
        view = visitorView
        
        setupNAV()
        
    }
    //设置导航栏的按钮
    private func setupNAV(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(highlightedImgName: nil, title: "注册", target: self, action: #selector(loginClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(highlightedImgName: nil, title: "登录", target: self, action: #selector(loginClick))
    }
    
    //监听按钮点击
    @objc private func loginClick(){
        
        // 未来弹出微博登录控制器
        let oauthVc = CZOAuthViewController()
        let oauthNavC = CZNavigationViewController(rootViewController: oauthVc)
        present(oauthNavC, animated: true, completion:  nil)
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    //懒加载控件
    lazy var tableView: UITableView = UITableView()

}
